window.onload = function(){
    let mydiv = document.getElementById("mydiv")
    console.log(typeof mydiv)
    
    if(mydiv instanceof HTMLElement){
        mydiv.style.backgroundColor = 'red'
        mydiv.style.padding = '20px'
        mydiv.style.textAlign = 'center'
        mydiv.style.cursor = 'pointer'
        
        // 设置初始文字
        mydiv.innerHTML = '点击我！'
        
        // 添加点击功能
        mydiv.onclick = function(){
            if(mydiv.style.backgroundColor === 'red'){
                mydiv.style.backgroundColor = 'blue'
                mydiv.innerHTML = '变成了蓝色！'
            } else {
                mydiv.style.backgroundColor = 'red' 
                mydiv.innerHTML = '又变回红色了！'
            }
        }
    }
}